{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Rotate String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string #string-matching"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串 #字符串匹配"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: rotateString"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #旋转字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给定两个字符串, <code>s</code>&nbsp;和&nbsp;<code>goal</code>。如果在若干次旋转操作之后，<code>s</code>&nbsp;能变成&nbsp;<code>goal</code>&nbsp;，那么返回&nbsp;<code>true</code>&nbsp;。</p>\n",
    "\n",
    "<p><code>s</code>&nbsp;的 <strong>旋转操作</strong> 就是将&nbsp;<code>s</code> 最左边的字符移动到最右边。&nbsp;</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如, 若&nbsp;<code>s = 'abcde'</code>，在旋转一次之后结果就是<code>'bcdea'</code>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> s = \"abcde\", goal = \"cdeab\"\n",
    "<strong>输出:</strong> true\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> s = \"abcde\", goal = \"abced\"\n",
    "<strong>输出:</strong> false\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示:</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length, goal.length &lt;= 100</code></li>\n",
    "\t<li><code>s</code>&nbsp;和&nbsp;<code>goal</code>&nbsp;由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [rotate-string](https://leetcode.cn/problems/rotate-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [rotate-string](https://leetcode.cn/problems/rotate-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abcde\"\\n\"cdeab\"', '\"abcde\"\\n\"abced\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        # n = len(s)\n",
    "        # for i in range(n):\n",
    "        #     s = s[1:n] + s[0]\n",
    "        #     if s == goal:\n",
    "        #         return True\n",
    "        # return False\n",
    "\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        if s in (goal + goal):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal + goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s)==len(goal) and s in (goal+goal)\n",
    "      \n",
    "       \n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal): # 两字符串可以不等长\n",
    "            return False\n",
    "        \n",
    "        for i in range(len(s)): # 旋转次数位于区间[ 0 , n - 1 ]内\n",
    "            if s[i:] + s[:i] == goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == goal[0]:\n",
    "                s1 = s[i:] + s[:i]\n",
    "                if s1 == goal:\n",
    "                    return True\n",
    "        return False\n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        n=len(s)\n",
    "        for i in range(n):\n",
    "            if (s[i:]+s[:i])==goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(goal) != len(s):\n",
    "            return False\n",
    "        s += s\n",
    "        return goal in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s)==len(goal) and s in (goal+goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        return goal in s+s \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        for i in range(len(goal)):\n",
    "            if goal[i:] + goal[0:i] == s:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        new_s = ''\n",
    "\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "\n",
    "        if s == goal:\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(1, len(s)):\n",
    "                new_s = s[i:] + s[:i]\n",
    "                if new_s == goal:\n",
    "                    return True\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        return s in goal * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        list1 = list(s)\n",
    "        list2 = list(goal)\n",
    "        count = 0\n",
    "        for i in range(len(s)):\n",
    "            count += 1\n",
    "            if list1 == list2:\n",
    "                return True\n",
    "            else:\n",
    "                list1.append(list1[0])\n",
    "                list1.remove(list1[0])\n",
    "        if count == len(s):\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "\n",
    "        # bf \n",
    "        # single pointer\n",
    "        # for each character:\n",
    "        #     move 1st item to last\n",
    "        #     a. check if converted matches goal\n",
    "        #     b. check if converted == original string\n",
    "        #     if match return true\n",
    "        #     else continue until moved != original word \n",
    "        \n",
    "        # return false \n",
    "\n",
    "        for i in range(len(s)):\n",
    "            convert = str(s[i+1:] + s[:i+1])\n",
    "            if convert == goal:\n",
    "                return True\n",
    "            \n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal + goal)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        # for i in range(len(s)):\n",
    "        #     s_new = s[i:]+s[:i]\n",
    "        #     if s_new == goal:\n",
    "        #         return True\n",
    "        # return False\n",
    "        return len(s) == len(goal) and s in (goal+goal)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s)==len(goal) and goal in (s+s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s+s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal+goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        s = 2 * s\n",
    "        return goal in s and len(goal) * 2 == len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal + goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        n = len(s)\n",
    "        s *= 2\n",
    "        for i in range(n):\n",
    "            if s[i:i+n] == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        result = False\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            if s == goal:\n",
    "                result = True\n",
    "                break\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        n = len(s)\n",
    "\n",
    "        if n!=len(goal):return False\n",
    "\n",
    "        for i in range(n):\n",
    "            # 每次偏移i个位置\n",
    "            for j in range(n):\n",
    "                if s[(i+j)%n]!=goal[j]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        l = 0\n",
    "        r = 1\n",
    "        n = 0\n",
    "        if len(goal) != len(s):\n",
    "            return False\n",
    "\n",
    "        while r <= len(goal):\n",
    "            if goal[l:r] in s:\n",
    "                r += 1\n",
    "            else:\n",
    "                l = r-1\n",
    "                n += 1 \n",
    "                if n >= 2:\n",
    "                    return False\n",
    "        return True \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        ans = list(s)\n",
    "        \n",
    "        for i in range(len(s)):\n",
    "            if ''.join(ans) != goal:\n",
    "                ans[1:] = reversed(ans[1:])\n",
    "                ans.reverse()\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal + goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        cmp = ''\n",
    "        N= len(s)\n",
    "        cnt = 0\n",
    "        for i in range(N):\n",
    "            cmp += s[-1] + s[:-1]\n",
    "            if cmp == goal:\n",
    "                return True\n",
    "            else:\n",
    "                cnt = i + 1\n",
    "                s = cmp\n",
    "            cmp = ''\n",
    "            if cnt == len(s):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)!=len(goal):\n",
    "            return False\n",
    "        else:\n",
    "            gg=goal+goal\n",
    "            return s in gg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in (s+s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        # if len(s) != len(goal): return False\n",
    "        # N = len(s)\n",
    "        # for _ in range(N):\n",
    "        #     s = s[1:]+s[0]\n",
    "        #     if s == goal: return True\n",
    "        # return False\n",
    "\n",
    "\n",
    "        return len(s) == len(goal) and s in (goal+goal)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        if s == goal:\n",
    "            return True\n",
    "        for i in range(len(s)):\n",
    "            if s[i:] + s[:i] == goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        m,n =len(s),len(goal)\n",
    "        if m !=n:\n",
    "            return False\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if s[(i+j) %n] != goal[j]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            if s[i + 1:] + s[:i + 1] == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and goal in s + s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        i=0\n",
    "        n=len(s)\n",
    "        while i<n:\n",
    "            if s[1:]+s[0]==goal:\n",
    "                return True\n",
    "            else:\n",
    "                s=s[1:]+s[0]\n",
    "            i+=1\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            ns = s[i + 1:] + s[:i+1]\n",
    "\n",
    "            if ns == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) == len(goal):\n",
    "            return (s+s).find(goal) >=0\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            if s[i + 1:] + s[:i + 1] == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        s2=list(s)\n",
    "        for i in range(len(s)):\n",
    "            s2.append(s2[0])\n",
    "            del s2[0]\n",
    "            if s2==list(goal):\n",
    "                return True\n",
    "        return False        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return goal in s*2 if len(s) == len(goal) else False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)==len(goal) and goal in s*2:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        for i in range(len(s)):\n",
    "            if s==goal:\n",
    "                return True\n",
    "            s+=s[0]\n",
    "            s=s[1:]\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            if s[i + 1:] + s[:i + 1] == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)!=len(goal):return False\n",
    "        return s in goal*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        #t = s\n",
    "        for i in range(len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            if s == goal:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)!=len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            if s[i]!=goal[0]:\n",
    "                continue\n",
    "            if s[i:]+s[:i]==goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s)==len(goal) and goal in (s+s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        if s in goal+goal:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            ns = s[i + 1:] + s[:i+1]\n",
    "\n",
    "            if ns == goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        n=len(s)\n",
    "        m=len(goal)\n",
    "        if m!=n:\n",
    "            return False\n",
    "        if (n==1)or(n==2):\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(n):\n",
    "                s1=s[:i:]\n",
    "                s2=s[i::]\n",
    "                s3=s2+s1\n",
    "                if s3==goal:\n",
    "                    return True\n",
    "            else:\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        ss = s[1:]\n",
    "        for i in s:\n",
    "            ss = ss + i\n",
    "            if ss == goal:\n",
    "                return True\n",
    "            else:\n",
    "                ss = ss[1:]\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        #t = s\n",
    "        for i in range(len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            if s == goal:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        n = len(s)\n",
    "        for i in range(n):\n",
    "            if s[i+1:] + s[:i+1] == goal:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)!=len(goal):\n",
    "            return False\n",
    "        else:\n",
    "            return s in (goal+goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        m, n = len(s), len(goal)\n",
    "        if m != n:\n",
    "            return False\n",
    "            \n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if s[(i + j) % n] != goal[j]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if s == goal:\n",
    "            return True\n",
    "        for i in range(1,len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            if s == goal:\n",
    "                return True\n",
    "        \n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        #t = s\n",
    "        for i in range(len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            print(s)\n",
    "            if s == goal:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        #t = s\n",
    "        for i in range(len(s)):\n",
    "            s = s[1:] + s[0]\n",
    "            if s == goal:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        # if len(s)!=len(goal): return False\n",
    "        # for _ in range(len(s)):\n",
    "        #     s = s[1:] + s[0]\n",
    "        #     if s==goal: return True\n",
    "        # return False\n",
    "        return len(s)==len(goal) and goal in (s+s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        n=len(s)\n",
    "        for i in range(n):\n",
    "            if s[i:]+s[:i]==goal:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal): return False\n",
    "        N = len(s)\n",
    "        for _ in range(N):\n",
    "            s = s[1:]+s[0]\n",
    "            if s == goal: return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s)!=len(goal):\n",
    "            return False\n",
    "        for i in range(len(s)):\n",
    "            if s[i]!=goal[0]:\n",
    "                continue\n",
    "            if s[i:]+s[:i]==goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal+goal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        return len(s) == len(goal) and s in (goal + goal)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "\n",
    "\n",
    "        n = len(s)\n",
    "\n",
    "        for i in range(n):\n",
    "\n",
    "\n",
    "            if s[i:] + s[:i] == goal:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import deque\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "\n",
    "        if s == goal:\n",
    "            return True\n",
    "\n",
    "        queue1 = deque(s)\n",
    "        queue2 = deque(goal)\n",
    "\n",
    "        for _ in range(len(s) - 1):\n",
    "            queue1.append(queue1.popleft())\n",
    "\n",
    "            if queue1 == queue2:\n",
    "                return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def rotateString(self, s: str, goal: str) -> bool:\n",
    "        if len(s) != len(goal):\n",
    "            return False\n",
    "        if s == goal:\n",
    "            return True\n",
    "        for j in range(1, len(s)):\n",
    "            if s[j:] + s[:j] == goal:\n",
    "                return True\n",
    "        return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
